package com.itheima.tcp4;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

//服务端
//BS框架
public class ServerDemo2 {
    public static void main(String[] args) throws Exception {
        //创建一个服务器
        ServerSocket ss = new ServerSocket(10086);
        ExecutorService pool =new ThreadPoolExecutor(3,10,10, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(100),
                Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        //调用accept方法 阻塞
        while (true) {
            Socket socket = ss.accept();
            System.out.println("一个客户端连接了"+socket.getInetAddress().getHostAddress());
            //创建一个线程
           pool.execute(new ServerReader(socket));
        }
    }
}
